home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / security / doc / clippings / 920206-01 < prev    next >
Encoding:
Internet Message Format  |  1992-03-20  |  1.8 KB

  1. From: mikel@demax.uucp (Mikel Lechner)
  2. Newsgroups: alt.security
  3. Subject: Re: Setuid shell scripts, Whats the problem?
  4. Message-ID: <1992Feb6.162413.6508@demax.uucp>
  5. Date: 6 Feb 92 16:24:13 GMT
  6. References: <1992Feb2.114728.27168@matilda.vut.edu.au> <1992Feb3.003936.9693@rz.uni-karlsruhe.de> <1992Feb03.191612.198991@cs.cmu.edu> <1992Feb4.170623.5192@aber.ac.uk>
  7. Organization: Demax Software Inc.
  8.  
  9. In <1992Feb4.170623.5192@aber.ac.uk> aem@aber.ac.uk (Alec David Muffett) writes:
  10.  
  11. >Actually guys, there is a simpler way to hack most setuid shell scripts...
  12.  
  13. >when the kernel is told to exec a shell script names [sic] "fred"
  14. >which contains the line "#!/bin/sh"
  15. >it builds the line "/bin/sh fred" 
  16. >goes setuid
  17. >and execs that...
  18.  
  19. >If you make a symlink to fred called "-i"
  20. >and execute "-i"
  21. >the kernel builds the line "/bin/sh -i"
  22. >goes setuid
  23. >and execs that...
  24.  
  25. This hole is plugged in SunOS (at least >= 4.0 & perhaps some other Unixes)
  26. in the C-shell by requiring that the flag "-b" appear in the "#!" line
  27. (ie. "#! /bin/csh -b").  If this flag is not present the C-shell refuses
  28. to execute SUID.  It does this check before it processes any flags.
  29. If you use the symlink spoof the resulting command line is "/bin/csh -b -i".
  30.  
  31. The "-b" flag has the additional effect that it causes all arguments which
  32. follow it to be passed to the shell script instead of being processed by
  33. the C-shell.  So, at least in this case, the symlink spoof is plugged.
  34.  
  35. However, you can still take advantage of the race condition between the
  36. exec() call and the open() of the script by the shell to trick it into
  37. running your own script as SUID the original script's owner.  I once wrote
  38. a program to test this.  It worked.  Then I removed all my SUID shell scripts.
  39.  
  40.  
  41. --
  42. Mikel Lechner                E-mail:        decwrl!demax!mikel
  43. Demax Software, Inc.            Phone:        (415) 341-9017
  44.